#include<bits/stdc++.h>
#define N 200010
using namespace std;
// long long f[N][3];
int n,T,s[N],ans;
inline void read(int &x)
{
    x = 0;
    int f = 1;
    char s= getchar();
    while(s < '0' || s > '9')
    {
        if(s == '-') f = -1;
        s = getchar();
    }
    while(s >= '0' && s <= '9')
    {
        x = x * 10 + s - 48;
        s = getchar();
    }
    x *= f;
    return;
}
inline void write(int x)
{
    if(x < 0)
    {
        putchar('-');
        x *= -1;
    }
    if(x > 9) write(x / 10);
    putchar(x % 10 + 48);
    return;
}
void dfs(int x,int co,int la,int lb,int g)
{
    // if(g <= f[x][0] && la < f[x][1] && lb < f[x][2]) return;
    // if(g > f[x][0])
    // {
    //     f[x][0] = g;
    //     f[x][1] = la;
    //     f[x][2] = lb;
    // }
    if(x == n)
    {
        g += (s[x] == s[(co == 1 ? lb : la)] ? s[x] : 0);
        ans = max(ans,g);
        return;
    }
    if(co == 0)
    {
        if(s[la] == s[x]) g += s[x];
        // ++ x;
        dfs(x + 1,0,x,lb,g);
        dfs(x + 1,1,x,lb,g);
        return;
    }
    if(s[lb] == s[x]) g += s[x];
    // ++ x;
    dfs(x + 1,0,la,x,g);
    dfs(x + 1,1,la,x,g);
    return;
}
inline void solve()
{
    ans = 0;
    dfs(1,0,0,0,0);
    dfs(1,1,0,0,0);
    write(ans);
    putchar('\n');
    return;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while(T --)
    {
        read(n);
        for(int i = 1;i <= n;i ++) read(s[i]);
        solve();
    }
    return 0;
}